#include "Generate_C_std.h"
#include "Pattern_assign_value.h"

/*
 * Assign_value is a specialization of Assign_var for assignments to a simple
 * zval which takes care of creating a new zval for the LHS.
 *
 * Assign_literal is a further specialization for those literal assignment
 * where the value of the literal is known at compile time (assigning a token
 * int, for example). The main difference between Assign_literal and 
 * Assign_zval is that Assign_literal can do constant pooling.
 */

void Pattern_assign_value::generate_code (Generate_C* gen)
{
  buf
    << get_st_entry (LOCAL, "p_lhs", lhs->value)
    << "zvalT value;\n"
    << "if ((*p_lhs)->is_ref)\n"
    << "{\n"
    << "  // Always overwrite the current value\n"
    << "  value = *p_lhs;\n"
    << "  zval_dtor (value);\n"
    << "}\n"
    << "else\n"
    << "{\n"
    <<	"	ALLOC_INIT_ZVAL (value);\n"
    <<	"	zval_ptr_dtor (p_lhs);\n"
    <<	"	*p_lhs = value;\n"
    << "}\n"
    ;
  
  initialize ("value");
}

//CREATE(Pattern_assign_value);
/**
src/codegen/Pattern_assign_value.cpp: In function »Pattern* createPattern_assign_value()«:
virtual MIR::Expr* Pattern_assign_var::rhs_pattern()
virtual void Pattern_assign_value::initialize(std::string)

**/
